class ProposalsController < ApplicationController
  def index
    @proposalsIveCreated = Proposal.find_all_by_requestor_id_and_workflow_state(current_user.id, :awaiting_approval)
    
    @proposalsImResponsibleFor = Proposal.find_proposals_by_responsibility current_user

    @proposalsAwaitingFinalApproval = Proposal.find_all_by_workflow_state(:awaiting_final_approval)
    
    @approvedProposals = Proposal.find_all_by_workflow_state(:approved)    
  end
  
  def show
    @proposal = Proposal.find(params[:id])    
    @roles = Role.all
  end
  
  def new
    @proposal = Proposal.new   
  end
  
  def create
    proposal = Proposal.new
    
    proposal.requestor = User.find(params[:proposal][:requestor])
    proposal.empoweringJurisdiction = Jurisdiction.find(params[:proposal][:empoweringJurisdiction])
    proposal.empoweredJurisdiction = Jurisdiction.find(params[:proposal][:empoweredJurisdiction])
    
    proposal.save
    
    redirect_to proposal_path(proposal.id)
  end
  
  def destroy
    proposal = Proposal.find(params[:id])
    proposal.destroy
    redirect_to proposals_url
  end
end
